using Engine;
using Game;
using Random = Game.Random;

namespace SCIENEW {
    /// <summary>
    /// 新地形生成类
    /// </summary>
    public class TerrainContentsGeneratorIE : TerrainContentsGenerator23, ITerrainContentsGenerator {
        static List<TerrainBrush> goldBrushes = [];
        static List<TerrainBrush> silverBrushes = [];
        static List<TerrainBrush> platinumBrushes = [];
        static List<TerrainBrush> leadBrushes = [];
        static List<TerrainBrush> zincBrushes = [];
        static List<TerrainBrush> stannaryBrushes = [];
        static List<TerrainBrush> mercuryBrushes = [];
        static List<TerrainBrush> chromiumBrushes = [];
        static List<TerrainBrush> titaniumBrushes = [];
        static List<TerrainBrush> nickelBrushes = [];
        static List<TerrainBrush> uraniumBrushes = [];
        static List<TerrainBrush> phosphorusBrushes = [];

        static TerrainContentsGeneratorIE() => CreateBrushesIE();
        public TerrainContentsGeneratorIE(SubsystemTerrain subsystemTerrain) : base(subsystemTerrain) { }

        public new void GenerateChunkContentsPass3(TerrainChunk chunk) {
            base.GenerateChunkContentsPass3(chunk);
            GenerateMineralsIE(chunk);
        }

        public new void GenerateChunkContentsPass4(TerrainChunk chunk) {
            base.GenerateChunkContentsPass4(chunk);
            GenerateFlax(chunk);
        }

        public void GenerateFlax(TerrainChunk chunk) {
            if (!TGExtras) {
                return;
            }
            Random random = new(m_seed + chunk.Coords.X + (1659 * chunk.Coords.Y));
            for (int x = 0; x < 16; x++) {
                for (int z = 0; z < 16; z++) {
                    for (int y = 250; y >= 0; y--) {
                        int cellValue = chunk.GetCellValueFast(x, y, z);
                        int cellValueP1 = chunk.GetCellValueFast(x, y + 1, z);
                        int cellValueP2 = chunk.GetCellValueFast(x, y + 2, z);
                        int cellValueP3 = chunk.GetCellValueFast(x, y + 3, z);
                        int cellID = Terrain.ExtractContents(cellValue);
                        int cellIDP1 = Terrain.ExtractContents(cellValueP1);
                        int cellIDP2 = Terrain.ExtractContents(cellValueP2);
                        int cellIDP3 = Terrain.ExtractContents(cellValueP3);
                        if (cellID != AirBlock.Index) {
                            if ((cellID is GrassBlock.Index)
                                && cellIDP1 is AirBlock.Index
                                && cellIDP2 is AirBlock.Index
                                && cellIDP3 is AirBlock.Index) {
                                int temperatureFast = chunk.GetTemperatureFast(x, z);
                                int humidityFast = chunk.GetHumidityFast(x, z);
                                GenerateFlaxAtPoint(chunk, temperatureFast, humidityFast, random, new Point3(x, y, z));
                            }
                            break;
                        }
                    }
                }
            }
        }

        private void GenerateFlaxAtPoint(TerrainChunk chunk, float temperature, float humidity, Random random, Point3 point) {
            float probability = random.Float(0f, 1f);
            float normalTemp = temperature / 0b1111;
            float normalHum = humidity / 0b1111;
            if (random.Float(0f, 1f) > normalHum
                || random.Float(0f, 1f) > (normalTemp > 0.5f ? (2 - 2 * normalTemp) : (2 * normalTemp))) {
                return;//适度越高越好，温度适中才好
            }
            if (probability < 0.03f) {
                chunk.SetCellValueFast(point.X, point.Y + 1, point.Z, NormalBlockManager.GetNormalBlockID("Flax_Stem_Ripened"));
                chunk.SetCellValueFast(point.X, point.Y + 2, point.Z, NormalBlockManager.GetNormalBlockID("Flax_Stem_Ripened"));
                chunk.SetCellValueFast(point.X, point.Y + 3, point.Z, NormalBlockManager.GetNormalBlockID("Flax_Top"));
            }
        }

        public void GenerateMineralsIE(TerrainChunk chunk) {
            if (!TGCavesAndPockets)
            {
                return; // 如果 TGCavesAndPockets 为 false，直接返回，不生成矿物
            }

            int chunkX = chunk.Coords.X; // 获取地形块的 X 坐标
            int chunkY = chunk.Coords.Y; // 获取地形块的 Y 坐标

            // 遍历周围的 9 个地形块，包括当前地形块及其周围的地形块
            //Zn
            for (int i = chunkX - 1; i <= chunkX + 1; i++)
            {
                for (int j = chunkY - 1; j <= chunkY + 1; j++)
                {
                    Random random = new Random(m_seed + i + (10086 * j)); // 使用种子值和当前地形块的坐标生成随机数生成器

                    int discardIterations = random.Int(0, 10); // 生成一个 0 到 10 之间的随机数
                    for (int k = 0; k < discardIterations; k++)
                    {
                        random.Int(0, 1); // 丢弃一些随机数，增加随机性
                    }
                    float mountainFactor = CalculateMountainRangeFactor(i * 16, j * 16); // 计算山脉因子
                    //Au
                    int auCount = (int)(OresDataBase.GetOreProbability(Materials.Gold) + (2f * mountainFactor * SimplexNoise.OctavedNoise(i + 12311, j + 12464, 0.33f, 1, 1f, 1f)));
                    for (int n = 0; n < auCount; n++)
                    {
                        int x4 = (i * 16) + random.Int(0, 15);
                        int y4 = random.Int(2, 40);
                        int z3 = (j * 16) + random.Int(0, 15);
                        goldBrushes[random.Int(0, goldBrushes.Count - 1)].PaintFastSelective(chunk, x4, y4, z3, 67);
                    }
                    //Ag
                    int agCount = (int)(OresDataBase.GetOreProbability(Materials.Silver) + (2f * mountainFactor * SimplexNoise.OctavedNoise(i + 1864, j + 28761, 0.33f, 1, 1f, 1f)));
                    for (int n = 0; n < agCount; n++)
                    {
                        int x4 = (i * 16) + random.Int(0, 15);
                        int y4 = random.Int(2, 40);
                        int z3 = (j * 16) + random.Int(0, 15);
                        silverBrushes[random.Int(0, silverBrushes.Count - 1)].PaintFastSelective(chunk, x4, y4, z3, 67);
                    }
                    //Pt
                    int ptCount = (int)(OresDataBase.GetOreProbability(Materials.Platinum) + (2f * mountainFactor * SimplexNoise.OctavedNoise(i + 12353454, j + 261, 0.33f, 1, 1f, 1f)));
                    for (int n = 0; n < ptCount; n++)
                    {
                        int x4 = (i * 16) + random.Int(0, 15);
                        int y4 = random.Int(2, 40);
                        int z3 = (j * 16) + random.Int(0, 15);
                        platinumBrushes[random.Int(0, platinumBrushes.Count - 1)].PaintFastSelective(chunk, x4, y4, z3, 67);
                    }
                    //Pb
                    int pbCount = (int)(OresDataBase.GetOreProbability(Materials.Lead) + (3f * mountainFactor * SimplexNoise.OctavedNoise(i + 1232, j + 8642, 0.33f, 1, 1f, 1f)));
                    for (int l = 0; l < pbCount; l++)
                    {
                        int x = (i * 16) + random.Int(0, 15); // 生成煤矿的 X 坐标
                        int y = random.Int(5, 200); // 生成煤矿的 Y 坐标
                        int z = (j * 16) + random.Int(0, 15); // 生成煤矿的 Z 坐标
                        leadBrushes[random.Int(0, leadBrushes.Count - 1)].PaintFastSelective(chunk, x, y, z, 3); // 使用随机选择的煤矿刷在地形块中生成煤矿
                    }
                    // 生成锌矿
                    int zincCount = (int)(OresDataBase.GetOreProbability(Materials.Zinc) + (3f * mountainFactor * SimplexNoise.OctavedNoise(i, j, 0.33f, 1, 1f, 1f)));
                    for (int l = 0; l < zincCount; l++)
                    {
                        int x = (i * 16) + random.Int(0, 15); // 生成煤矿的 X 坐标
                        int y = random.Int(5, 200); // 生成煤矿的 Y 坐标
                        int z = (j * 16) + random.Int(0, 15); // 生成煤矿的 Z 坐标
                        zincBrushes[random.Int(0, zincBrushes.Count - 1)].PaintFastSelective(chunk, x, y, z, 3); // 使用随机选择的煤矿刷在地形块中生成煤矿
                    }
                    //Sn
                    int snCount = (int)(OresDataBase.GetOreProbability(Materials.Stannary) + (3f * mountainFactor * SimplexNoise.OctavedNoise(i + 6442, j + 2437, 0.33f, 1, 1f, 1f)));
                    for (int l = 0; l < snCount; l++)
                    {
                        int x = (i * 16) + random.Int(0, 15); // 生成煤矿的 X 坐标
                        int y = random.Int(5, 200); // 生成煤矿的 Y 坐标
                        int z = (j * 16) + random.Int(0, 15); // 生成煤矿的 Z 坐标
                        stannaryBrushes[random.Int(0, stannaryBrushes.Count - 1)].PaintFastSelective(chunk, x, y, z, 3); // 使用随机选择的煤矿刷在地形块中生成煤矿
                    }
                    //Hg
                    int hgCount = (int)(OresDataBase.GetOreProbability(Materials.Mercury) + (2f * mountainFactor * SimplexNoise.OctavedNoise(i + 5597, j + 122, 0.33f, 1, 1f, 1f)));
                    for (int n = 0; n < hgCount; n++)
                    {
                        int x4 = (i * 16) + random.Int(0, 15);
                        int y4 = random.Int(2, 40);
                        int z3 = (j * 16) + random.Int(0, 15);
                        mercuryBrushes[random.Int(0, mercuryBrushes.Count - 1)].PaintFastSelective(chunk, x4, y4, z3, 67);
                    }
                    //生成铬矿
                    int crCount = (int)(OresDataBase.GetOreProbability(Materials.Chromium) + (2f * mountainFactor * SimplexNoise.OctavedNoise(i + 1231, j + 1241, 0.33f, 1, 1f, 1f)));
                    for (int n = 0; n < crCount; n++)
                    {
                        int x4 = (i * 16) + random.Int(0, 15);
                        int y4 = random.Int(2, 40);
                        int z3 = (j * 16) + random.Int(0, 15);
                        chromiumBrushes[random.Int(0, chromiumBrushes.Count - 1)].PaintFastSelective(chunk, x4, y4, z3, 67);
                    }
                    //Ti
                    int tiCount = (int)(OresDataBase.GetOreProbability(Materials.Titanium) + (2f * mountainFactor * SimplexNoise.OctavedNoise(i + 1214, j + 18764, 0.33f, 1, 1f, 1f)));
                    for (int n = 0; n < tiCount; n++)
                    {
                        int x4 = (i * 16) + random.Int(0, 15);
                        int y4 = random.Int(2, 40);
                        int z3 = (j * 16) + random.Int(0, 15);
                        titaniumBrushes[random.Int(0, titaniumBrushes.Count - 1)].PaintFastSelective(chunk, x4, y4, z3, 67);
                    }
                    //Ni
                    int niCount = (int)(OresDataBase.GetOreProbability(Materials.Nickel) + (2f * mountainFactor * SimplexNoise.OctavedNoise(i + 8523, j + 9564, 0.33f, 1, 1f, 1f)));
                    for (int n = 0; n < niCount; n++)
                    {
                        int x4 = (i * 16) + random.Int(0, 15);
                        int y4 = random.Int(2, 40);
                        int z3 = (j * 16) + random.Int(0, 15);
                        nickelBrushes[random.Int(0, nickelBrushes.Count - 1)].PaintFastSelective(chunk, x4, y4, z3, 67);
                    }
                    //U
                    int uCount = (int)(OresDataBase.GetOreProbability(Materials.Uranium) + (2f * mountainFactor * SimplexNoise.OctavedNoise(i + 742, j + 98, 0.33f, 1, 1f, 1f)));
                    for (int n = 0; n < uCount; n++)
                    {
                        int x4 = (i * 16) + random.Int(0, 15);
                        int y4 = random.Int(2, 40);
                        int z3 = (j * 16) + random.Int(0, 15);
                        uraniumBrushes[random.Int(0, uraniumBrushes.Count - 1)].PaintFastSelective(chunk, x4, y4, z3, 67);
                    }
                    //P
                    int pCount = (int)(OresDataBase.GetOreProbability(Materials.Phosphorus) + (3f * mountainFactor * SimplexNoise.OctavedNoise(i + 6295, j + 345, 0.33f, 1, 1f, 1f)));
                    for (int l = 0; l < pCount; l++)
                    {
                        int x = (i * 16) + random.Int(0, 15); // 生成煤矿的 X 坐标
                        int y = random.Int(5, 200); // 生成煤矿的 Y 坐标
                        int z = (j * 16) + random.Int(0, 15); // 生成煤矿的 Z 坐标
                        phosphorusBrushes[random.Int(0, phosphorusBrushes.Count - 1)].PaintFastSelective(chunk, x, y, z, 3); // 使用随机选择的煤矿刷在地形块中生成煤矿
                    }
                }
            }
        }

        public static void CreateBrushesIE() {
            Random random = new Random(37); // 创建一个随机数生成器，并指定种子值为 27
            //Zn
            for (int brushIndex = 0; brushIndex < 16; brushIndex++) {// 循环 16 次，生成 16 个 TerrainBrush 对象
                TerrainBrush terrainBrush = new TerrainBrush();// 创建一个新的 TerrainBrush 对象
                int boxGroupCount = random.Int(4, 12);// 随机生成盒子的组数，范围在 4 到 12 之间

                for (int groupIndex = 0; groupIndex < boxGroupCount; groupIndex++) {// 循环 boxGroupCount 次，生成多个盒子组
                    Vector3 direction = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)));// 生成一个随机向量，并将其归一化然后乘以 0.5
                    int boxesPerGroup = random.Int(3, 8);// 随机生成每组盒子的数量，范围在 3 到 8 之间
                    Vector3 currentPosition = Vector3.Zero;// 初始化一个起始位置向量
                    for (int boxIndex = 0; boxIndex < boxesPerGroup; boxIndex++) {// 循环 boxesPerGroup 次，在当前组中添加多个盒子
                        terrainBrush.AddBox(
                            (int)MathF.Floor(currentPosition.X),
                            (int)MathF.Floor(currentPosition.Y),
                            (int)MathF.Floor(currentPosition.Z),
                            1,
                            1,
                            1,
                            OresBlock.SetBlockID(Materials.Zinc, false, false)
                        );// 向 terrainBrush 中添加一个 1x1x1 的盒子，位置由 currentPosition 确定
                        currentPosition += direction;// 将 currentPosition 向 direction 方向移动
                    }
                }
                terrainBrush.Compile();// 编译地形刷
                zincBrushes.Add(terrainBrush);// 将地形刷添加到列表中
            }
            //Au
            for (int brushIndex = 0; brushIndex < 16; brushIndex++)
            {
                TerrainBrush terrainBrush2 = new();
                int boxGroupCount = random.Int(3, 7);
                for (int m = 0; m < boxGroupCount; m++)
                {
                    Vector3 vector2 = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)));
                    int boxesPerGroup = random.Int(1, 4);
                    Vector3 zero2 = Vector3.Zero;
                    for (int n = 0; n < boxesPerGroup; n++)
                    {
                        terrainBrush2.AddBox((int)MathF.Floor(zero2.X), (int)MathF.Floor(zero2.Y), (int)MathF.Floor(zero2.Z), 1, 1, 1, OresBlock.SetBlockID(Materials.Gold, false, false));
                        zero2 += vector2;
                    }
                }
                terrainBrush2.Compile();
                goldBrushes.Add(terrainBrush2);
            }
            //Ag
            for (int brushIndex = 0; brushIndex < 16; brushIndex++)
            {
                TerrainBrush terrainBrush2 = new();
                int boxGroupCount = random.Int(3, 7);
                for (int m = 0; m < boxGroupCount; m++)
                {
                    Vector3 vector2 = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)));
                    int boxesPerGroup = random.Int(2, 5);
                    Vector3 zero2 = Vector3.Zero;
                    for (int n = 0; n < boxesPerGroup; n++)
                    {
                        terrainBrush2.AddBox((int)MathF.Floor(zero2.X), (int)MathF.Floor(zero2.Y), (int)MathF.Floor(zero2.Z), 1, 1, 1, OresBlock.SetBlockID(Materials.Silver, false, false));
                        zero2 += vector2;
                    }
                }
                terrainBrush2.Compile();
                silverBrushes.Add(terrainBrush2);
            }
            //Pt
            for (int brushIndex = 0; brushIndex < 16; brushIndex++)
            {
                TerrainBrush terrainBrush2 = new();
                int boxGroupCount = random.Int(3, 7);
                for (int m = 0; m < boxGroupCount; m++)
                {
                    Vector3 vector2 = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)));
                    int boxesPerGroup = random.Int(1, 4);
                    Vector3 zero2 = Vector3.Zero;
                    for (int n = 0; n < boxesPerGroup; n++)
                    {
                        terrainBrush2.AddBox((int)MathF.Floor(zero2.X), (int)MathF.Floor(zero2.Y), (int)MathF.Floor(zero2.Z), 1, 1, 1, OresBlock.SetBlockID(Materials.Platinum, false, false));
                        zero2 += vector2;
                    }
                }
                terrainBrush2.Compile();
                platinumBrushes.Add(terrainBrush2);
            }
            //Pb
            for (int brushIndex = 0; brushIndex < 16; brushIndex++) {// 循环 16 次，生成 16 个 TerrainBrush 对象
                TerrainBrush terrainBrush = new TerrainBrush();// 创建一个新的 TerrainBrush 对象
                int boxGroupCount = random.Int(4, 12);// 随机生成盒子的组数，范围在 4 到 12 之间

                for (int groupIndex = 0; groupIndex < boxGroupCount; groupIndex++) {// 循环 boxGroupCount 次，生成多个盒子组
                    Vector3 direction = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)));// 生成一个随机向量，并将其归一化然后乘以 0.5
                    int boxesPerGroup = random.Int(3, 8);// 随机生成每组盒子的数量，范围在 3 到 8 之间
                    Vector3 currentPosition = Vector3.Zero;// 初始化一个起始位置向量
                    for (int boxIndex = 0; boxIndex < boxesPerGroup; boxIndex++) {// 循环 boxesPerGroup 次，在当前组中添加多个盒子
                        terrainBrush.AddBox(
                            (int)MathF.Floor(currentPosition.X),
                            (int)MathF.Floor(currentPosition.Y),
                            (int)MathF.Floor(currentPosition.Z),
                            1,
                            1,
                            1,
                            OresBlock.SetBlockID(Materials.Lead, false, false)
                        );// 向 terrainBrush 中添加一个 1x1x1 的盒子，位置由 currentPosition 确定
                        currentPosition += direction;// 将 currentPosition 向 direction 方向移动
                    }
                }
                terrainBrush.Compile();// 编译地形刷
                leadBrushes.Add(terrainBrush);// 将地形刷添加到列表中
            }
            //Sn
            for (int brushIndex = 0; brushIndex < 16; brushIndex++) {// 循环 16 次，生成 16 个 TerrainBrush 对象
                TerrainBrush terrainBrush = new TerrainBrush();// 创建一个新的 TerrainBrush 对象
                int boxGroupCount = random.Int(4, 12);// 随机生成盒子的组数，范围在 4 到 12 之间

                for (int groupIndex = 0; groupIndex < boxGroupCount; groupIndex++) {// 循环 boxGroupCount 次，生成多个盒子组
                    Vector3 direction = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)));// 生成一个随机向量，并将其归一化然后乘以 0.5
                    int boxesPerGroup = random.Int(3, 8);// 随机生成每组盒子的数量，范围在 3 到 8 之间
                    Vector3 currentPosition = Vector3.Zero;// 初始化一个起始位置向量
                    for (int boxIndex = 0; boxIndex < boxesPerGroup; boxIndex++) {// 循环 boxesPerGroup 次，在当前组中添加多个盒子
                        terrainBrush.AddBox(
                            (int)MathF.Floor(currentPosition.X),
                            (int)MathF.Floor(currentPosition.Y),
                            (int)MathF.Floor(currentPosition.Z),
                            1,
                            1,
                            1,
                            OresBlock.SetBlockID(Materials.Stannary, false, false)
                        );// 向 terrainBrush 中添加一个 1x1x1 的盒子，位置由 currentPosition 确定
                        currentPosition += direction;// 将 currentPosition 向 direction 方向移动
                    }
                }
                terrainBrush.Compile();// 编译地形刷
                stannaryBrushes.Add(terrainBrush);// 将地形刷添加到列表中
            }
            //Cr
            for (int brushIndex = 0; brushIndex < 16; brushIndex++)
            {
                TerrainBrush terrainBrush2 = new();
                int boxGroupCount = random.Int(3, 7);
                for (int m = 0; m < boxGroupCount; m++)
                {
                    Vector3 vector2 = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)));
                    int boxesPerGroup = random.Int(3, 6);
                    Vector3 zero2 = Vector3.Zero;
                    for (int n = 0; n < boxesPerGroup; n++)
                    {
                        terrainBrush2.AddBox((int)MathF.Floor(zero2.X), (int)MathF.Floor(zero2.Y), (int)MathF.Floor(zero2.Z), 1, 1, 1, OresBlock.SetBlockID(Materials.Chromium, false, false));
                        zero2 += vector2;
                    }
                }
                terrainBrush2.Compile();
                chromiumBrushes.Add(terrainBrush2);
            }
            //Hg
            for (int brushIndex = 0; brushIndex < 16; brushIndex++)
            {
                TerrainBrush terrainBrush2 = new();
                int boxGroupCount = random.Int(3, 7);
                for (int m = 0; m < boxGroupCount; m++)
                {
                    Vector3 vector2 = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)));
                    int boxesPerGroup = random.Int(3, 6);
                    Vector3 zero2 = Vector3.Zero;
                    for (int n = 0; n < boxesPerGroup; n++)
                    {
                        terrainBrush2.AddBox((int)MathF.Floor(zero2.X), (int)MathF.Floor(zero2.Y), (int)MathF.Floor(zero2.Z), 1, 1, 1, OresBlock.SetBlockID(Materials.Mercury, false, false));
                        zero2 += vector2;
                    }
                }
                terrainBrush2.Compile();
                mercuryBrushes.Add(terrainBrush2);
            }
            //Ti
            for (int brushIndex = 0; brushIndex < 16; brushIndex++)
            {
                TerrainBrush terrainBrush2 = new();
                int boxGroupCount = random.Int(3, 7);
                for (int m = 0; m < boxGroupCount; m++)
                {
                    Vector3 vector2 = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)));
                    int boxesPerGroup = random.Int(3, 6);
                    Vector3 zero2 = Vector3.Zero;
                    for (int n = 0; n < boxesPerGroup; n++)
                    {
                        terrainBrush2.AddBox((int)MathF.Floor(zero2.X), (int)MathF.Floor(zero2.Y), (int)MathF.Floor(zero2.Z), 1, 1, 1, OresBlock.SetBlockID(Materials.Titanium, false, false));
                        zero2 += vector2;
                    }
                }
                terrainBrush2.Compile();
                titaniumBrushes.Add(terrainBrush2);
            }
            //Ni
            for (int brushIndex = 0; brushIndex < 16; brushIndex++)
            {
                TerrainBrush terrainBrush2 = new();
                int boxGroupCount = random.Int(3, 7);
                for (int m = 0; m < boxGroupCount; m++)
                {
                    Vector3 vector2 = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)));
                    int boxesPerGroup = random.Int(3, 6);
                    Vector3 zero2 = Vector3.Zero;
                    for (int n = 0; n < boxesPerGroup; n++)
                    {
                        terrainBrush2.AddBox((int)MathF.Floor(zero2.X), (int)MathF.Floor(zero2.Y), (int)MathF.Floor(zero2.Z), 1, 1, 1, OresBlock.SetBlockID(Materials.Nickel, false, false));
                        zero2 += vector2;
                    }
                }
                terrainBrush2.Compile();
                nickelBrushes.Add(terrainBrush2);
            }
            //U
            for (int brushIndex = 0; brushIndex < 16; brushIndex++)
            {
                TerrainBrush terrainBrush2 = new();
                int boxGroupCount = random.Int(3, 7);
                for (int m = 0; m < boxGroupCount; m++)
                {
                    Vector3 vector2 = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)));
                    int boxesPerGroup = random.Int(3, 6);
                    Vector3 zero2 = Vector3.Zero;
                    for (int n = 0; n < boxesPerGroup; n++)
                    {
                        terrainBrush2.AddBox((int)MathF.Floor(zero2.X), (int)MathF.Floor(zero2.Y), (int)MathF.Floor(zero2.Z), 1, 1, 1, OresBlock.SetBlockID(Materials.Uranium, false, false));
                        zero2 += vector2;
                    }
                }
                terrainBrush2.Compile();
                uraniumBrushes.Add(terrainBrush2);
            }
            //P
            for (int brushIndex = 0; brushIndex < 16; brushIndex++) {
                // 循环 16 次，生成 16 个 TerrainBrush 对象
                TerrainBrush terrainBrush = new TerrainBrush(); // 创建一个新的 TerrainBrush 对象
                int boxGroupCount = random.Int(4, 12); // 随机生成盒子的组数，范围在 4 到 12 之间
                for (int groupIndex = 0; groupIndex < boxGroupCount; groupIndex++) {
                    // 循环 boxGroupCount 次，生成多个盒子组
                    Vector3 direction = 0.5f * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f))); // 生成一个随机向量，并将其归一化然后乘以 0.5
                    int boxesPerGroup = random.Int(3, 8); // 随机生成每组盒子的数量，范围在 3 到 8 之间
                    Vector3 currentPosition = Vector3.Zero; // 初始化一个起始位置向量
                    for (int boxIndex = 0; boxIndex < boxesPerGroup; boxIndex++) {
                        // 循环 boxesPerGroup 次，在当前组中添加多个盒子
                        terrainBrush.AddBox(
                            (int)MathF.Floor(currentPosition.X),
                            (int)MathF.Floor(currentPosition.Y),
                            (int)MathF.Floor(currentPosition.Z),
                            1,
                            1,
                            1,
                            OresBlock.SetBlockID(Materials.Phosphorus, false, false)
                        ); // 向 terrainBrush 中添加一个 1x1x1 的盒子，位置由 currentPosition 确定
                        currentPosition += direction; // 将 currentPosition 向 direction 方向移动
                    }
                }
                terrainBrush.Compile(); // 编译地形刷
                phosphorusBrushes.Add(terrainBrush); // 将地形刷添加到列表中
            }
        }
    }
}